package org.manusoft.refill.view;

import java.io.Serializable;

import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;

import org.manusoft.refill.domain.TRefillingDetailsRf;
import org.manusoft.refill.service.AllotmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

@Component("viewMovie")
@Scope("view")
public class ViewMovie implements Serializable {

    private TRefillingDetailsRf refillingDetails;
    private AllotmentService allotmentService;
    private Integer allotmentID;

    public Integer getMovieId() {
        return allotmentID;
    }

    public ViewMovie() {
    }

    @Autowired
    public ViewMovie(AllotmentService movieService) {
        this.allotmentService = movieService;
    }

    public void onLoad() {
        refillingDetails = allotmentService.findById(allotmentID,false);
    }

    public TRefillingDetailsRf getMovie() {
        return refillingDetails;
    }

    public void setMovieId(Integer allotmentID) {
        this.allotmentID = allotmentID;
    }

    public void setMovie(TRefillingDetailsRf movie) {
        this.refillingDetails = movie;
    }

    public void update() {
        allotmentService.createAllotment(refillingDetails);
        FacesMessage facesMessage = new FacesMessage(FacesMessage.SEVERITY_INFO, "Movie is updated successfully", "OK");
        FacesContext.getCurrentInstance().addMessage(null, facesMessage);
    }

    public String remove() {
        allotmentService.delete(refillingDetails);
        return "manageMovies?faces-redirect=true";
    }
}
